// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import axios from 'axios'
import VueAxios from 'vue-axios'
import VuePreview from 'vue-preview'
import 'element-ui/lib/theme-chalk/index.css'
import { config } from 'shelljs'

//创建axios实例，用自己的配置
const _axios = axios.create({
  transformRequest: [function (data) {
      // 将数据转换为表单数据
      let ret = ''
      for (let it in data) {
          ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
  }],
  headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
  }
});


Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(VueAxios,_axios)
Vue.use(VuePreview)

/*获取token保存到session*/
_axios.interceptors.request.use(config=>{
  config.headers.Authorization=window.sessionStorage.getItem('guid');
  config.headers.Authorization=window.sessionStorage.getItem('token');
  console.log("请求头",window.sessionStorage.getItem('token'));
  return config;
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

